﻿using Power.ViewModel.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Power.View.Report
{
    /// <summary>
    /// 成果表
    /// </summary>
    public partial class AchievementTable : UserControl
    {
        public AchievementTable()
        {
            InitializeComponent();
            this.DataContext = new AchievementTableViewModel(this);
            
        }
       
        public void Init()
        {
            var title = new List<string>()
            {
                "项目代码",
                "子项",
                "片区代码",
                "区块代码",
                "工点名称",
                "起始井号",
                "终止井号",
                "地区参数",
                "土质参数",
                "敷设年代",
                "管段类型",
                "管段材质",
                "管段直径",
                "管段长度",
                "检测长度",
                "起点埋深",
                "终点埋深",
                "缺陷起始位置",
                "缺陷终止位置",
                "缺陷长度",
                "环向",
                "缺陷类型",
                "缺陷名称",
                "缺陷代码",
                "缺陷等级",
                "检测图片",
                "检测描述",
                "检测方法",
                "检测方向",
                "检测日期",
                "检测批次",
                "检测员",
                "分包商",
                "序号",
                "S",
                "Smax",
                "缺陷参数",
                "F等级",
                "缺陷密度",
                "SM类型",
                "修复指数",
                "修复等级",
                "修复建议",
                "Y",
                "Ymax",
                "缺陷参数",
                "G等级",
                "缺陷密度",
                "YM类型",
                "养护指数",
                "养护等级",
            };
            var row = 10;
            for (int i = 0; i < row; i++)
            {
                this.table.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });

            }
            for (int i = 0; i < title.Count; i++)
            {
                this.table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100) });
            }

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < title.Count; j++)
                {
                    var label = new Label();
                    label.HorizontalContentAlignment = HorizontalAlignment.Center;
                    label.VerticalContentAlignment = VerticalAlignment.Center;
                    label.FontSize = 13;

                    var border = new Border();
                    border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                    border.BorderThickness = new Thickness(1, 1, 0, 0);

                    Grid.SetRow(label, i);
                    Grid.SetColumn(label, j);

                    Grid.SetRow(border, i);
                    Grid.SetColumn(border, j);

                    if (i < 3)
                    {
                        label.Background = new SolidColorBrush(Color.FromRgb(247, 248, 251));

                    }

                    if (i == 0 && j == 0)
                    {
                        //设置表名称
                        label.Content = "排水管段内窥检测与评估成果表";
                        Grid.SetColumnSpan(label, title.Count);
                        this.table.Children.Add(label);
                    }
                    else if (i == 0)
                    {
                        border.BorderThickness = new Thickness(0, 1, 0, 0);
                    }

                    if (i == 1 && j < 12)
                    {
                        label.Content = title[j];
                        Grid.SetRowSpan(label, 2);
                        this.table.Children.Add(label);
                    }

                    if (i == 2 && j < 12)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    if (i == 1 && j >= 12 && j <= 16)
                    {
                        label.Content = title[j];
                        this.table.Children.Add(label);
                    }


                    if (i == 2 && j == 12)
                    {
                        label.Content = "m";
                        Grid.SetColumnSpan(label, 5);
                        this.table.Children.Add(label);
                    }
                    else if (i == 2 && j > 12 && j <= 16)
                    {
                        border.BorderThickness = new Thickness(0, 1, 0, 0);
                    }

                    //缺陷起始位置-序号
                    if (i == 1 && j > 16 && j < 34)
                    {
                        label.Content = title[j];
                        Grid.SetRowSpan(label, 2);
                        this.table.Children.Add(label);
                    }
                    if (i == 2 && j > 16 && j < 34)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    //结构性
                    if (i == 1 && j == 34)
                    {
                        label.Content = "结构性";
                        Grid.SetColumnSpan(label, 9);
                        this.table.Children.Add(label);
                    }
                    if (i == 1 && j > 34 && j <= 42)
                    {
                        border.BorderThickness = new Thickness(0, 1, 0, 0);
                    }

                    if (i == 2 && j >= 34 && j <= 42)
                    {
                        label.Content = title[j];
                        this.table.Children.Add(label);
                    }

                    //功能性
                    if (i == 1 && j == 43)
                    {
                        label.Content = "功能性";
                        Grid.SetColumnSpan(label, 8);
                        this.table.Children.Add(label);
                    }
                    if (i == 1 && j > 43)
                    {
                        border.BorderThickness = new Thickness(0, 1, 0, 0);
                    }

                    if (i == 2 && j >= 43)
                    {
                        label.Content = title[j];
                        this.table.Children.Add(label);
                    }

                    ////if (j == title.Count - 1)
                    ////{
                    ////    border.BorderThickness = new Thickness(0, 0, 1, 0);
                    ////}
                    ////if (i == row-1)
                    ////{
                    ////    border.BorderThickness = new Thickness(1, 1, 0, 1);
                    ////}

                    ////if (i == 0 && j == title.Count - 1)
                    ////{
                    ////    border.BorderThickness = new Thickness(0, 1, 1, 0);
                    ////}
                    this.table.Children.Add(border);
                }
            }

            //补边框
            for (int i = 0; i < row; i++)
            {
                var border = new Border();
                border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                border.BorderThickness = new Thickness(0, 0, 1, 0);
                Grid.SetRow(border, i);
                Grid.SetColumn(border, title.Count - 1);
                this.table.Children.Add(border);
            }
            for (int i = 0; i < title.Count; i++)
            {
                var border = new Border();
                border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                border.BorderThickness = new Thickness(0, 0, 0, 1);
                Grid.SetRow(border, row - 1);
                Grid.SetColumn(border, i);
                this.table.Children.Add(border);
            }
        }
    }
}
